<!--
 * @Description: 
 * @Author: jun.wu
 * @Date: 2022-10-19 16:32:16
 * @LastEditors: jun.wu
 * @LastEditTime: 2022-11-17 11:28:37
-->
<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <!-- 左侧内容 -->
      <span>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 放置下拉菜单 -->
          <el-dropdown @command="operateDepts">
            <!-- 内容 -->
            <span
              >操作
              <i class="el-icon-arrow-down" />
            </span>
            <!-- 具名插槽 -->
            <el-dropdown-menu slot="dropdown">
              <!-- 下拉选项 -->
              <el-dropdown-item
                command="add"
                :disablied="!checkPermission('add-dept')"
                >添加子部门</el-dropdown-item
              >
              <el-dropdown-item v-if="!isRoot" command="edit"
                >编辑部门</el-dropdown-item
              >
              <el-dropdown-item v-if="!isRoot" command="del"
                >删除部门</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>

      <!-- 右侧内容 -->
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from "@/api/departments";
export default {
  props: {
    //定义传入的属性
    treeNode: {
      required: true, //使用组件时必须传treeNode属性，不然报错
      type: Object,
    },
    isRoot: {
      type: Boolean,
      default: false,
    },
  },

  methods: {
    //点击新增，编辑，删除
    operateDepts(type) {
      if (type === "add") {
        // 新增
        this.$emit("addDepts", this.treeNode);
      } else if (type === "edit") {
        // 编辑
        this.$emit("editDepts", this.treeNode);
      } else {
        // 删除
        this.$confirm("您确定要删除该组织部门吗?")
          .then(() => {
            return delDepartments(this.treeNode.id);
          })
          .then(() => {
            //调用接口删除成功,前端还没变化,前端重新获取
            this.$emit("delDepts");
            this.$message.success("删除部门成功");
          });
      }
    },
  },
};
</script>

<style></style>
